import Nav from '../../src/components/common/nav/nav.vue'
import {ApiUrl,Islogined,returnId,show,hide} from './ApiUrl.js'
import loading from '../../src/components/common/loading/loading.vue'
import fangerror from '../../src/components/common/fangerror/fangerror.vue'
import Swiper from '../plugins/swiper4x/swiper.min'
import Vue from 'vue'
import VueScroller from 'vue-scroller'
Vue.use(VueScroller)
require('./corAPI');
import {timerScale} from '../plugins/scale/self_adaption_scale'
require("./lib/select2/js/select2.min");
export default {
  components: {
    meun:Nav,loading,fangerror,
  },
  data(){
    return {
      FangLoading:false,//Loading控制，true显示，false不显示
      fangerroring:false,//提示文本弹窗，true显示，false不显示
      fangerrorText:'',//提示文本弹窗内容
      subStatus:true,
      imgUrl:'./static/images/',
      imgPng:'.png',
      indexListPage:1,//主列表页码数
      keyword:'',
      specialtyCode:'',
      specialtyindex:'',//专业下标
      noData:'',
      indexCode:'',
      industryCode:null,//专业类型

      //搜索历史
      lastKeywordList:[
        {keyword:""},
      ],

      //专业分类
      majorSwiperList:[
        {indexName:""},
      ],

      //常用指标
      engineeringList:[],

    }
  },
  created: function() {

  },
  mounted(){
    let _This = this;
    timerScale();
    /*//指标
    this.engineIndex(null,true,null,true,1,10,function (data) {
      _This.engineeringList = data;
    });*/
    this.specialtyCode = this.$route.query.specialtyCode;
    this.specialtyindex = this.$route.query.index;
    this.industryCode = this.$route.query.industryCode;

    //指标
    this.engineIndex(null,true,_This.specialtyCode,true,1,10,function (data) {
      _This.engineeringList = data;
    });
    //专业
    this.majorSwiper(_This.industryCode,true,null,1,30,function (data) {
      _This.majorSwiperList = data;
      setTimeout(() => {
        var swiper = new Swiper('.swiper-container-major', {
          slidesPerView: 'auto',
          spaceBetween: 10,
          initialSlide:_This.specialtyindex,
        });
        /*let majorSwiperBoxDom = _This.$refs.majorSwiperBox
        console.log(majorSwiperBoxDom.children[0].children[specialtyindex].classList.add('chooseIconActive'))*/
      }, 20)
    })

    /*
    kw,refCount,page,pageSize
    * */
    this.lastKeyword(100,function (data) {
      _This.lastKeywordList = data;
      console.log(data)
    })

   /* let windowH = $(window).height();
    let meunBoxH = $('.meunBox').outerHeight(true);
    let megessBoxH = $('.megessBox').outerHeight(true);
    $('.contentLeft,.contentRight').height( windowH - meunBoxH - megessBoxH );
    $('.tabContentBox').height(windowH - meunBoxH);*/


  },
  methods:{
    setTimeoutError:function () {
      setTimeout(() => {
        $('.Fang_errorBox').hide()
        this.fangerroring = false
      }, 2000)
    },

    //返回
    back:function () {
      this.$router.back(-1);
    },

    /* 搜索历史 */
    lastKeyword:function (pageSize,fn) {
      this.FnAxiosAjax('POST','/api/history/lastkeyword',{pageSize},function (data) {
        !! fn && fn(data.results);
      })
    },

    //选中分类样式改变并切换内容
    bindClickIschooseIcon:function(e,indexCode){
      let _This = this;
      let eT = e.currentTarget;
      _This.specialtyCode = indexCode;
      _This.$refs.indexsublist.scrollTo(0,0,false);
      let childDom  = eT.parentNode.childNodes;
      /*console.log(eT.parentNode.childNodes);*/
      for(let i = 0;i < childDom.length;i++){
        childDom[i].classList.remove('chooseIconActive');//先删除所有含有active 类名
      }
      eT.classList.add('chooseIconActive');//单独添加active 类名
      this.engineIndex(_This.keyword,true,indexCode,true,1,30,function (data) {
        _This.engineeringList = data;

      })
      //return
    },

    /* 指标数据 */
    engineIndex:function (kw,subStatus,specialtyCode,refCount,page,pageSize,fn) {
      this.FnAxiosAjax('post','/api/indexcategory/list',{kw,subStatus,specialtyCode,refCount,page,pageSize},function
        (data) {
        !!fn && fn(data.results);
      })
    },


    //上拉加载更多数据
    infinite(done) {
      let _This = this;
      if(this.noData) {
        setTimeout(() => {
          _This.$refs.indexsublist.finishInfinite(2);
        })
        return;
      }
      _This.indexListPage =  _This.indexListPage + 1;
      setTimeout(() => {

        _This.engineIndex(_This.keyword,true,_This.specialtyCode,true,_This.indexListPage,10,function (data) {
          if(data=='' || data == null){
            done(true);//没有更多数据
            /*this.noData = ''*/
          }else {
            done();
          }
          if(_This.engineeringList == ''){
            _This.engineeringList = data;
          }else {
            for(let key in data){
              _This.engineeringList.push(data[key]);
            }
          }
        })
      }, 500)
    },

    /* 专业 */
    majorSwiper:function (industryCode,subStatus,indexType,page,pageSize,fn) {
      this.FnAxiosAjax('post','/api/indexcategory/querybyindustrycode',
        {industryCode,subStatus,indexType,page,pageSize},function (data) {
          !! fn && fn(data.results);
        })
    },

    //选中回传
    chooseNorm:function (items) {
      items.subStatus = !items.subStatus;
      this.FnAxiosAjax('post','/api/indexcategory/updateSubStatus',
        {
          specialtyCode:items.specialtyCode,
          indexCode:items.indexCode,
          indexType:items.indexType
    },function (data) {

        })
    },

    //获取ID并跳转
    detail:function (index,indexCode,indexType,refCount) {
      if(refCount !=0 ){
        this.$router.push({path:'detail?id='+ index+'&indexCode='+indexCode+'&indexType='+indexType});
      }else {
        this.fangerroring = true;
        this.fangerrorText = '暂无指标详情';
        this.setTimeoutError();
      }
    },


    /*
    * 搜索
    *keywords	true	string		搜索词
    SCHOOL_ID	False	String		id
    * */
    BtnSerachClick:function () {
      let _This = this;
      _This.lastKeyword(100,function (data) {
        _This.lastKeywordList = data;
      });
      _This.keyword = $('.serachInput').val().trim();
      this.engineIndex(_This.keyword,null,_This.specialtyCode,true,1,10,function (data) {
        _This.engineeringList = data;
      });
    },

  }
}

